<template>
  <div/>
</template>

<script>
import Qs from 'qs'
export default {
  data() {
    return {
      ts: this.newStore(),
      username: ''
    }
  },
  mounted() {
    const query = Qs.parse(window.location.search.substring(1))
    const code = query.code
    if (code && code != '') {
      // 从微信转回，进行服务器登录
      this.doLogin(code)
      return
    }
    // }

    // // 判断登录
    this.getWxCode()
  },
  methods: {
    getWxCode() {
      const wxLoginUrl =
        'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf30a6608e950a663&redirect_uri=http://vipcard.eke88.com/login&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
      // 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf30a6608e950a663&redirect_uri=http://vipcard.eke88.com&response_type=code&scope=snsapi_userinfo&state=1&connect_redirect=1#wechat_redirect'

      // 改成ajax试试
      window.location = wxLoginUrl
    },
    doLogin(code) {
      const res = {
        code: code
      }
      this.spost(this.ts, '/Register/getWeixinCode', res).then(ts => {
        // if (ts.d.flag == '200') {
        console.log(ts.d.data)
        // localStorage.setItem('token', ts.d.data.token)
        // console.log(localStorage.getItem('token'))
        // localStorage.setItem('identity', ts.d.data.identity)
        // this.$router.push({ name: 'ephome' })
        // }
        this.$router.push({ name: 'fhome' })
      })
      console.log('doLogin', code)
    }
  }
}
</script>

<style>
</style>
